package physicsModeler.objects;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

abstract class Sprite extends DrawObject {
	
	/* Sprite class data members
	 * 
	 */
	
	protected MediaTracker mediaTracker;
	protected ImageObserver imageObserver;
	protected BufferedImage image,offScreenImage;
	protected Rectangle bounds;
	protected String imageFile;
	protected int width,height,rows,cols;
	protected BufferedImage[] sprites;

	/* Sprite class constructors
	 * 
	 */
	public Sprite()
	{
		
		
	}
	
	// Loads images for all created sprites;
	protected BufferedImage loadImages()
	{
		try 
		{
		    image = ImageIO.read(new File(imageFile));
		    sprites = new BufferedImage[rows * cols];
		    
		    for (int i = 0; i < rows; i++)
		    {
		        for (int j = 0; j < cols; j++)
		        {
		            try {
						sprites[(i * cols) + j] = image.getSubimage(
						    i * width,
						    10,
						    width,
						    height
						);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						break;
					}
		        }
		    }

		} 
		catch (IOException e) 
		{
		}

		return image;
	}

	@Override
	abstract public void draw(Graphics g);
	
	
	@Override
	abstract public String getName();

	
}
